package org.liquidByte.trafficMustang.androidApp.listview.adapter;

import org.liquidByte.trafficMustang.R;
import org.liquidByte.trafficMustang.androidApp.listview.row.ListViewRow;
import org.liquidByte.trafficMustang.androidApp.listview.row.PassageiroRow;
import org.liquidByte.trafficMustang.androidApp.listview.row.RowActionListener;
import org.liquidByte.trafficMustang.androidApp.services.dto.TrechoDTO;

import android.content.Context;
import android.view.View;

public class PassageiroRowAdapter extends RowAdapter<TrechoDTO> {

	private RowActionListener<PassageiroRow> localizacaoActionListener;
	
	public PassageiroRowAdapter(Context ctx) {
		super(ctx);
	}

	@Override
	public long getItemId(int position) {
		TrechoDTO trecho = (TrechoDTO)this.getItem(position);
		if (trecho == null) {
			return 0;
		} else {
			return trecho.getId();
		}
	}

	@Override
	protected int getViewResource() {
		return R.layout.listview_row_passageiro;
	}
	
	public void setLocalizacaoActionListener(
			RowActionListener<PassageiroRow> localizacaoActionListener) {
		this.localizacaoActionListener = localizacaoActionListener;
	}

	@Override
	protected ListViewRow createRow(View view) {
		PassageiroRow row = new PassageiroRow(this, view);
		row.setLocalizacaoActionListener(new RowActionListener<PassageiroRow>() {
			@Override
			public void actionPerformed(PassageiroRow row) {
				PassageiroRowAdapter adapter = PassageiroRowAdapter.this;
				if (adapter.localizacaoActionListener != null) {
					adapter.localizacaoActionListener.actionPerformed(row);
				}
			}
		});
		return row;
	}

}
